package managment;

import java.util.ArrayList;
import java.util.Iterator;
import view.View;

/**
 * @author  Owner
 */
@SuppressWarnings("unchecked")
public class Manager {

	private static Manager instance;
	
	private ArrayList<Comparable[]> target;
	
	/**
	 * @return  the instance
	 * @uml.property  name="instance"
	 */
	public static Manager getInstance(){
		if(instance==null)
			instance=new Manager();
		return instance;
	}
	
	private Manager(){}
	
	public static void main(String[] args) {
		
		//testing the generated arrays:
//		ArraySource mySrc;
//		try {
//			mySrc = ArraySource.getSuitableInstance(InType.auto,//type 
//					10, //maximum size of arrays
//					Prop.random);//suitable parameter according to type
//			target = mySrc.createTarget();
//			printTarget();
//		} catch (MyException e) {
//			e.handle();
//		}
		
		
		//testing reading from files:
//	    ArraySource mySrc;
//		try {
//			mySrc = ArraySource.getSuitableInstance(InType.file,//type 
//					10, //maximum size of arrays
//					"E:\\New Folder (10)");//suitable parameter according to type
//			target = mySrc.createTarget();
//			printTarget();
//		} catch (MyException e) {
//			e.handle();
//		}
		
	}
	
	public  void printTarget(){

		Iterator <Comparable[]> iter=target.iterator();
		while(iter.hasNext()){
			Comparable[] temp=iter.next();
			for (int i = 0; i < temp.length; i++) {
				System.out.print((Integer)temp[i]+", ");
			}
			System.out.println();
		}
	}

	public void addToList(ArrayList<Comparable[]> childList){
	    if(this.target==null){
		    this.target=new ArrayList<Comparable[]>();
		    this.target.addAll(childList);
		}		
		else{ 
		    this.target.addAll(childList);
		}
		
		View.getInstance().updatelist(this.target);
		System.out.println("==================================");
		printTarget();
		System.out.println("==================================");
	}
	
	public Comparable[] getWorkArray(int index){
	    return this.target.get(index);
	}
}
